package pl.edu.pw.elka.tinyrepo.client.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.sql.Date;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;

import pl.edu.pw.elka.tinyrepo.common.FileProperties;

/**
 * 
 * @author Anna Stępień
 * @version 13-12-2011
 *
 */
class ResourcePropertiesPanel extends JPanel
{
	private JLabel fileNameLabel;
	private JLabel lengthLabel;
	private JLabel lastModifiedLabel;
	
	private JLabel fileNameLabelValue;
	private JLabel lengthLabelValue;
	private JLabel lastModifiedLabelValue;
	
	private JPanel labelPane;
	private JPanel labelValuePane;
	
	public ResourcePropertiesPanel()
	{
		setPreferredSize(new Dimension(300, 480));
		setLayout(new BorderLayout());
		
		fileNameLabel = new JLabel("File Name: ");
		lengthLabel = new JLabel("File length: ");
		lastModifiedLabel = new JLabel("Last modified: ");
		
		fileNameLabelValue = new JLabel();
		lengthLabelValue = new JLabel();
		lastModifiedLabelValue = new JLabel();
		
		
        labelPane = new JPanel(new GridLayout(0,1));
        labelPane.add(fileNameLabel);
        labelPane.add(lengthLabel);
        labelPane.add(lastModifiedLabel);

 
        labelValuePane = new JPanel(new GridLayout(0,1));
        labelValuePane.add(fileNameLabelValue);
        labelValuePane.add(lengthLabelValue);
        labelValuePane.add(lastModifiedLabelValue);
        
        setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        add(labelPane, BorderLayout.CENTER);
        add(labelValuePane, BorderLayout.LINE_END);
        
        labelPane.setVisible(false);
        labelValuePane.setVisible(false);
	}

	public void displayProperties(FileProperties properties)
	{
        labelPane.setVisible(true);
        labelValuePane.setVisible(true);
        
		fileNameLabelValue.setText(properties.getFilename());
		lengthLabelValue.setText(Long.toString(properties.getLength()));
		String lmodified = new Date(properties.getLastModified()).toString();
		if(properties.getLastModified() == 0) 
		   lmodified = "None (directory)";
		lastModifiedLabelValue.setText(lmodified);

	}
}
